package cloud.maque.module.system.service.impl;

import cloud.maque.module.system.entity.SysUserDept;
import cloud.maque.module.system.mapper.UserDeptMapper;
import cloud.maque.module.system.service.UserDeptService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserDeptServiceImpl extends ServiceImpl<UserDeptMapper, SysUserDept> implements UserDeptService {
    @Override
    public List<SysUserDept> GetList(SysUserDept data) {
        QueryWrapper<SysUserDept> query = new QueryWrapper<>();
        if (!StrUtil.isEmptyIfStr(data.getDeptId())) {
            query.lambda().eq(SysUserDept::getDeptId, data.getDeptId());
        }
        if (!StrUtil.isEmptyIfStr(data.getUserId())) {
            query.lambda().like(SysUserDept::getUserId, data.getUserId());
        }
        return this.list(query);
    }

    @Override
    public SysUserDept SaveUserDept(SysUserDept data) {
        this.saveOrUpdate(data);
        return data;
    }

    @Override
    public void SaveBatch(List<SysUserDept> data) {
        this.saveBatch(data);
    }

    @Override
    public Boolean DeleteByDeptId(String deptId) {
        QueryWrapper<SysUserDept> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SysUserDept::getDeptId, deptId);
        return this.remove(queryWrapper);
    }

    @Override
    public Boolean DeleteByUserId(String userId) {
        QueryWrapper<SysUserDept> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SysUserDept::getUserId, userId);
        return this.remove(queryWrapper);
    }
}
